﻿#include "VirtualTradeLib.h"
#include "TradeOrderIO.h"



VirtualTradeLib::VirtualTradeLib()
{
}


VirtualTradeLib::~VirtualTradeLib()
{
}

void VirtualTradeLib::InsertOrderNow(const TD::OrderOption &pOption, TD::OrderBackFunc pBackFunc)
{

}

bool VirtualTradeLib::GetPositionDetail(const std::string &pSymbol, QryData::Position &outPos)
{
	return false;
}

bool VirtualTradeLib::GetOrderDetail(const std::string &pSymbol, TD::Order &outOrder)
{
	std::map<std::string, TD::Order>::iterator it = m_orders.find(pSymbol);
	if (it == m_orders.end())
	{
		return false;
	}
	outOrder = it->second;
	return true;
}

bool VirtualTradeLib::UpdateOrderDetail(const std::string &pSymbol, const TD::Order &pOrder)
{
	m_orders[pSymbol] = pOrder;
	TradeOrderIO orderIO;
	orderIO.Save(m_orders);
	return true;
}

bool VirtualTradeLib::EraseOrderDetail(const std::string &pSymbol)
{
	if (m_orders.empty())
	{
		return false;
	}
	std::map<std::string, TD::Order>::iterator itOrder = m_orders.find(pSymbol);
	if (itOrder == m_orders.end())
	{
		return false;
	}
	m_orders.erase(itOrder);
	TradeOrderIO orderIO;
	orderIO.Save(m_orders);
	return true;
}
